package com.wn.ticket.web;

import cn.hutool.core.util.RandomUtil;
import com.wn.ticket.common.PageBean;
import com.wn.ticket.common.ResponseEntity;
import com.wn.ticket.entity.Perform;
import com.wn.ticket.service.PerformService;
import com.wn.ticket.vo.PerformVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/front/perform")
public class WebPerformController {
    @Autowired
    private PerformService performService;
    @GetMapping("/getByHot")
    public ResponseEntity getByHot(){
        List<Perform> list = performService.getByHot();

        return new ResponseEntity(list);
    }

    @GetMapping("/getById/{id}")
    public ResponseEntity getByHot(@PathVariable int id){
        Perform perform = performService.getById(id);

        return new ResponseEntity(perform);
    }

    @RequestMapping("/getGuess")//随机获取演出
    public ResponseEntity getGuess(){
        List<Perform> performList = performService.getAll();
        if (performList.size()>10){
            Collections.shuffle(performList);//打乱集合顺序
            performList = performList.subList(0, 9);//获取前10个数
        }


        return new ResponseEntity(performList);
    }

    @PostMapping("/getPage")
    public ResponseEntity getPage(@RequestBody PerformVo performVo) {
        PageBean<Perform> pageBean =  performService.getPageByCondition(performVo.getPerform(), performVo.getCurrPage(), performVo.getPageSize());

        return new ResponseEntity(pageBean);
    }

    @PostMapping("/getOrderBy")
    public ResponseEntity getOrderBy(@RequestBody PerformVo performVo) {
        List<Perform> list = performService.getOrderByPrice(performVo.getPerform(), performVo.getOrderBy());

        return new ResponseEntity(list);
    }


}
